#include <at89c51RC2.h>
#include <Timer0.h>
#include <Key.h>
#include <Nixie.h>

sbit Motor=P1^0;

unsigned char Counter,Compare;
unsigned char KeyNum,Speed;
 
void main()
{
	Motor=0;
	Timer0_Init();
	while(1)
	{
		KeyNum=Key();
		if(KeyNum==1)
		{
			Speed++;
			Speed%=4;
			if(Speed==0) {Compare=0;}
			if(Speed==1) {Compare=50;}
			if(Speed==2) {Compare=75;}
			if(Speed==3) {Compare=100;}
		}
		Nixie(1,Speed);
	}
}

void Timer0_Routine() interrupt 1  //溢出时中断
{
	TL0 = 0xAE;		
	TH0 = 0xFB;
	Counter++;
	Counter%=100;    //Counter到100了
	if(Counter<Compare)
	{
		Motor=1;
	}
	else
	{
		Motor=0;
	}
}